package com.heo.coder.packet;

import com.heo.coder.packet.base.BasePacket;
import com.heo.util.ByteHelper;

public class AttributePacketRsp extends BasePacket{

	public AttributePacketRsp(String commandId, String reserve, String subcontract, String rsa, int bodyLength, String imei,
			String sequenceId, String body, String check) throws Exception {
		super(commandId, reserve, subcontract, rsa, bodyLength, imei, sequenceId, body, check);
	}
	
	/**
	 * 查询终端属性
	 */
	public void queryAttribute() {
		body = "";
		int bodyInt = 0;
		String binary = reserve + subcontract + rsa + ByteHelper.hex10To2String(bodyInt, 10);
		String hex = ByteHelper.binaryString2hexString(binary);
		setHead(hex);
		setBodyLength(bodyInt);
		
		String hexCheck = getCommandId() + head + imei + sequenceId + body;
    	byte[] hexCheckBytes = ByteHelper.hexStringToBytes(hexCheck);
		byte xorByte = ByteHelper.getXor(hexCheckBytes);
		String checkCodeStr = ByteHelper.byteToHexString(new byte[] {xorByte});
		check = checkCodeStr;
	}
	 
	@Override
	public String toString() {
		return "SocketPacket: [" + commandId + "] [" + START_MARKER_LENGTH_CODE + getCommandId() + getHead() + getImei() + getSequenceId() + getBody() + getCheck() + END_MARKER_LENGTH_CODE + "]";
	}

	@Override
	public String getPacketBody() {
		return super.body;
	}

	
	
}
